<?php

declare (strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Controller\user;

use App\Dao\PlatformDao;
use App\Dao\PlatformOrderDao;
use App\Dao\UserAddrDao;
use App\Request\User\Channel\ChannelBuyRequest;
use App\Request\User\UserAddr\CreateRequest;
use App\Request\User\UserAddr\EditRequest;
use App\Middleware\User\UserMiddleware;

use App\Service\User\ChannelService;
use App\Service\User\PlatformOrderService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Middleware;

/**
 * 渠道商控制器
 *
 * @AutoController()
 * @Middleware(UserMiddleware::class)
 * @author 张昊(2396675557@qq.com)
 * @package App\Controller\user
 */
    class ChannelController extends Controller
{

    /**
     * 平台商品Dao
     * @Inject
     * @var PlatformDao
     */
    private $platform_dao;


    /**
     * 平台订单服务
     * @Inject
     * @var PlatformOrderService
     */
    private $platform_order_service;

    /**
     * 渠道商服务
     * @Inject
     * @var ChannelService
     */
    public $channel_service;

    /**
     * 渠道商手动分佣
     */
    public function Manual()
    {
        $order_no = (string)$this->request->input('order_no', 0);

        $this->platform_order_service->channel($order_no);

        $this->success();
    }

    /**
     * 获取渠道商
     *
     */
    public function get()
    {
        $result = $this->platform_dao->first([
            'type' => $this->platform_dao::TYPE_CHANNEL
        ]);

        $this->success($result);
    }

    /**
     * 购买渠道商
     *
     * @return mixed
     */
    public function buy()
    {
        $id = (int)$this->request->input('id', 0);

        $channel = (string)$this->request->input('channel', 0);

        $result = $this->platform_order_service->buy($id, $channel);

        $this->success($result);
    }


    /**
     * 渠道商列表
     *
     */
    public function list()
    {
        $type = (int)$this->request->input('type', 0);

        if ($type === 0) $this->error();

        $result = $this->channel_service->list( $type );

        $this->success( $result );
    }

    /**
     *  渠道商推广列表 - 渠道商
     */
    public function channelList()
    {
        $start_time = (string)$this->request->input('start_time', 0);

        if ($start_time === 0) $this->error();

        $result = $this->channel_service->channelList($start_time);

        $this->success($result);
    }

    /**
     * 渠道商推广列表 - 会员
     */
    public function userList()
    {
        $start_time = (string)$this->request->input('start_time', 0);

        if ($start_time === 0) $this->error();

        $result = $this->channel_service->userList($start_time);

        $this->success($result);
    }

    /**
     * 渠道商推广列表 - 商家
     */
    public function businessList()
    {
        $start_time = (string)$this->request->input('start_time', 0);

        if ($start_time === 0) $this->error();

        $result = $this->channel_service->businessList($start_time);

        $this->success($result);
    }
}